﻿package plugin.instances.game
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.net.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.mornExtends.*;

    public class YxfmgGame extends YxfmgUI implements IInstance
    {
        private var score:int = 0;
        private var nextFreshTime:int = 0;

        public function YxfmgGame()
        {
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            if (param2[InstancesPublic.YXFMGINIT])
            {
                this.updateShow(InstancesPublic.YXFMGINIT, param2[InstancesPublic.YXFMGINIT]);
            }
            else
            {
                txt_wave.text = "0";
                txt_exp.text = "0";
                txt_kills.text = "0";
                txt_state.text = "未刷新";
                txt_nexttime.text = "- -";
                this.score = 0;
            }
            this.showItem(param1.show);
            shuoming.toolTip = param1.tips.replace(/#""#/g, "\n");
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list.array = _loc_3[0];
            list.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = list.array[param2];
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 < 0)
                    {
                        _loc_4 = 0;
                    }
                    if (txt_wave.text != "12")
                    {
                        txt_nexttime.text = TimeDataFormatUtil.getLeftTime(_loc_4);
                    }
                    else
                    {
                        txt_nexttime.text = "怪物已全部击杀";
                    }
                    if (_loc_4 == 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:4, value:30});
                    }
                    txt_time.text = TimeDataFormatUtil.getLeftTime(int(param2));
                    break;
                }
                case InstancesPublic.YXFMGINIT:
                {
                    txt_wave.text = param2.wave;
                    this.nextFreshTime = param2.nextFreshTime;
                    if (param2.wave == 12)
                    {
                        this.nextFreshTime = 0;
                    }
                    txt_exp.text = param2.exp;
                    this.showBossState(param2.BOSS);
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 < 0)
                    {
                        _loc_4 = 0;
                    }
                    if (txt_wave.text != "12")
                    {
                        txt_nexttime.text = TimeDataFormatUtil.getLeftTime(_loc_4);
                    }
                    else
                    {
                        txt_nexttime.text = "怪物已全部击杀";
                    }
                    if (_loc_4 < 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    txt_kills.text = param2.killnum;
                    this.score = param2.killnum;
                    break;
                }
                case InstancesPublic.YXFMGWAVE:
                {
                    txt_wave.text = param2.wave;
                    this.nextFreshTime = param2.nextFreshTime;
                    if (param2.wave == 12)
                    {
                        this.nextFreshTime = 0;
                    }
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 < 0)
                    {
                        _loc_4 = 0;
                    }
                    if (_loc_4 <= 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    if (txt_wave.text != "12")
                    {
                        txt_nexttime.text = TimeDataFormatUtil.getLeftTime(_loc_4);
                    }
                    else
                    {
                        txt_nexttime.text = "怪物已全部击杀";
                    }
                    break;
                }
                case InstancesPublic.YXFMGCHANGE:
                {
                    txt_exp.text = param2.exp;
                    ModelProxy.change("mainui", "bmRunAdd", {type:2, count:param2.killnum - Number(txt_kills.text)});
                    txt_kills.text = param2.killnum;
                    this.score = param2.killnum;
                    break;
                }
                case InstancesPublic.YXFMGNEXTWAVETIME:
                {
                    this.nextFreshTime = int(param2);
                    if (txt_wave.text == "12")
                    {
                        this.nextFreshTime = 0;
                    }
                    _loc_3 = Number(ModelProxy.getValue("data", "servertime") + getTimer()) / 1000;
                    _loc_4 = this.nextFreshTime - _loc_3;
                    if (_loc_4 < 0)
                    {
                        _loc_4 = 0;
                    }
                    if (txt_wave.text != "12")
                    {
                        txt_nexttime.text = TimeDataFormatUtil.getLeftTime(_loc_4);
                    }
                    else
                    {
                        txt_nexttime.text = "已结束";
                    }
                    if (_loc_4 <= 30)
                    {
                        ModelProxy.change("mainui", "counter", {type:6, value:_loc_4});
                    }
                    break;
                }
                case InstancesPublic.YXFMGBOSSSTATE:
                {
                    this.showBossState(int(param2));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function showBossState(param1:int) : void
        {
            txt_state.removeEventListener(MouseEvent.CLICK, this.doRemove);
            switch(param1)
            {
                case 1:
                {
                    txt_state.addEventListener(MouseEvent.CLICK, this.doRemove);
                    txt_state.text = "<font color=\'#53b436\'><u>已出现</u></font>";
                    break;
                }
                case 2:
                {
                    txt_state.text = "<font color=\'#c72514\'>已击杀</font>";
                    break;
                }
                default:
                {
                    txt_state.text = "<font color=\'#c72514\'>未刷新</font>";
                    break;
                    break;
                }
            }
            return;
        }// end function

        protected function doRemove(event:MouseEvent) : void
        {
            Server.instance.sendBuffer(102, CMDStage.ResFMGBossPositionMessage, null, 0, ConnectType.SYSTEM);
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            return;
        }// end function

        public function initEvent() : void
        {
            btn_tuichu.clickHandler = new Handler(this.doTuichu);
            return;
        }// end function

        private function doTuichu() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
